//
//  ShuJiXiangQing_TableViewCell.m
//  iBook
//
//  Created by apple on 15/1/19.
//  Copyright (c) 2015年 wikiflyer. All rights reserved.
//

#import "ShuJiXiangQing_TableViewCell.h"
#import <QuartzCore/QuartzCore.h>
#import "CommonFunc.h"


#define MRScreenHeight     CGRectGetHeight([UIScreen mainScreen].applicationFrame)
#define MRScreenWidth      CGRectGetWidth([UIScreen mainScreen].applicationFrame)

@implementation ShuJiXiangQing_TableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)initCell1theImage:(NSString *)theImage shuming:(NSString *)theShuMing zuozhe:(NSString *)theZuoZhe time:(NSString *)theTime yeshu:(NSString *)theYeShu daxiao:(NSString *)theDaXiao jiage:(NSString *)theJiaGe{\
    
    NSData* dataImage = [CommonFunc dataWithBase64EncodedString:theImage];
    UIImageView * imageV=[[UIImageView alloc] initWithFrame:CGRectMake(12, 12, 55, 84)];
    imageV.image=[UIImage imageWithData:dataImage];
    [self addSubview:imageV];
    
    UILabel * lable1=[[UILabel alloc] initWithFrame:CGRectMake(12+55+12, 12, MRScreenWidth-12-55-12-39, 42)];
    lable1.numberOfLines=0;
    lable1.text=theShuMing;
    [self addSubview:lable1];
    
    UILabel * lable2=[[UILabel alloc] initWithFrame:CGRectMake(79, 54, MRScreenWidth-12-55-12-39, 21)];
    lable2.textColor=[UIColor lightGrayColor];
    lable2.font=[UIFont systemFontOfSize:12];
    lable2.text=theZuoZhe;
    [self addSubview:lable2];
    
    UILabel * lable3=[[UILabel alloc] initWithFrame:CGRectMake(79, 54+21, MRScreenWidth-12-55-12-39, 21)];
    lable3.textColor=[UIColor lightGrayColor];
    lable3.font=[UIFont systemFontOfSize:12];
    lable3.text=theTime;
    [self addSubview:lable3];
    
    UILabel * lable4=[[UILabel alloc] initWithFrame:CGRectMake(79, 54+21+21, 50, 21)];
    lable4.textColor=[UIColor lightGrayColor];
    lable4.font=[UIFont systemFontOfSize:12];
    lable4.text=theYeShu;
    [self addSubview:lable4];
    
    UILabel * lable5=[[UILabel alloc] initWithFrame:CGRectMake(79+50, 54+21+21, 80, 21)];
    lable5.font=[UIFont systemFontOfSize:14];
    lable5.text=theDaXiao;
    [self addSubview:lable5];
    
    UILabel * lable6=[[UILabel alloc] initWithFrame:CGRectMake(MRScreenWidth-80, 54+21+10-35, 60, 21)];
    lable6.textColor=[UIColor lightGrayColor];
    lable6.font=[UIFont systemFontOfSize:14];
    lable6.text=[NSString stringWithFormat:@"¥%@",theJiaGe];
    [self addSubview:lable6];
    
    UIButton * btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.layer.cornerRadius = 6;
    btn.layer.borderColor = [UIColor colorWithRed:23/255.f green:126/255.f blue:251/255.f alpha:1].CGColor;
    btn.layer.borderWidth = 2;
    btn.frame=CGRectMake(MRScreenWidth-60, 54+21+10, 50, 30);
    [btn setTitle:@"获取" forState:UIControlStateNormal];
    [self addSubview:btn];
    
}
-(void)initCell2:(NSString *)theMiaoShu{
    self.delegate=self;
    UILabel * label1=[[UILabel alloc] initWithFrame:CGRectMake(12, 15, 80, 21)];
    label1.text=@"图书描述";
    [self addSubview:label1];
    
    lable2X=[[UILabel alloc] initWithFrame:CGRectMake(12, 15+21+15, MRScreenWidth-24, 50)];
    lable2X.numberOfLines=0;
    lable2X.textColor=[UIColor lightGrayColor];
    lable2X.font=[UIFont systemFontOfSize:12];
    lable2X.text=theMiaoShu;
    _strLabel2X=lable2X.text;
    [self addSubview:lable2X];
    
    btnX=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnX.frame=CGRectMake(MRScreenWidth-50, 120-21, 40, 21);
    [btnX setTitle:@"更多" forState:UIControlStateNormal];
    [btnX addTarget:self action:@selector(goBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnX];
    
}
#pragma mark - btn
-(void)goBtn1:(UIButton *)sender{
    sender.hidden=YES;
    
    CGSize maxSize = CGSizeMake(self.frame.size.width, CGFLOAT_MAX);
    CGSize textSize;
    if ([lable2X.text respondsToSelector:@selector(sizeWithAttributes:)]) {
        textSize = [lable2X.text boundingRectWithSize:maxSize
                                           options:NSStringDrawingUsesLineFragmentOrigin
                                        attributes:@{NSFontAttributeName: lable2X.font}
                                           context:nil].size;
    }
    CGRect labelRect = lable2X.frame;
    labelRect.size.height = ceil(textSize.height);
    [lable2X setFrame:labelRect];
        
    if ([_delegate respondsToSelector:@selector(ShuJiXiangQing_TableViewCell_Detegate:theHeight:indexPath:)]) {
        [_delegate ShuJiXiangQing_TableViewCell_Detegate:self theHeight:(lable2X.frame.size.height+15+21+15+30)indexPath:nil];
    }
    
    
}



@end
